class InterruptHandler:

	def __init__(self, kernel):
		self.kernel = kernel

	def interrupt(self, signal):

		self.kernel.lock.acquire()
		self.kernel.kernelMode = True
		
		try:
			if signal is 'exit':
				print('[signal] exit pid %s'%(self.kernel.current_pid))
				self.kernel.exitProgram()
				self.kernel.reschedule()
			elif signal is 'timeOut':
				print('[signal] timeOut')
				self.kernel.io()
				self.kernel.reschedule()
			elif signal is 'ioReq':
				print('[signal] io_req')
				self.kernel.io()
				self.kernel.reschedule()
			elif signal is 'kill':
				print('[signal] kill')
				self.interrupt('exit')
			elif signal is 'new':
				print('[signal] new')
				if self.kernel.idle():
					self.kernel.reschedule()
			else: # wrong signal, process terminated
				self.interrupt('exit')
		finally:
			self.kernel.kernelMode = False
			self.kernel.lock.release()
			